import axios from 'axios';
const http = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 5000, //代表请求超过当前时间，没有相应就结束
});

http.interceptors.request.use(config => {
  return config;
});
// 响应拦截器
http.interceptors.response.use(
  res => {
    console.log(res.config, '响应拦截');
    if (res.config.url == '/selectByDataBase' || res.config.url == '/selectDataBase') {
      res.data.data.records.forEach((item: any) => {
        if (item.baseStatus == '1') {
          item.baseStatus = '未发布';
        } else if (item.baseStatus == '2') {
          item.baseStatus = '已发布';
        } else if (item.baseStatus == '3') {
          item.baseStatus = '已停用';
        }
      });
      console.log(res.data.data.records);
    }
    return res;
  },
  err => {
    return err;
  },
);

export default http;
